
/*
 * Copyright (C) 2009 Archie L. Cobbs. All rights reserved.
 *
 * $Id: XMLDateField.java 190 2009-11-12 19:54:20Z archie.cobbs $
 */

package org.dellroad.sidekar.xml;

import java.util.Date;

import org.dellroad.sidekar.DateField;

/**
 * Container for a {@link DateField}'s value during the Sidekar XML import/export process.
 */
class XMLDateField extends XMLAtomicField<Date> {

    private Date value;
    private boolean isNull;

    // Used during unmarshalling
    private XMLDateField(XMLItem xmlItem) {
        super(xmlItem);
    }

    // Used during unmarshalling
    private XMLDateField(XMLField xmlField) {
        super(xmlField);
    }

    // Used during marshalling
    public XMLDateField(String name, Date value) {
        super(name);
        this.value = value;
        this.isNull = value == null;
    }

    // Used during unmarshalling
    @Override
    public Date getObjectValue() {
        return this.isNull ? null : this.value;
    }

    // Used during unmarshalling
    public static XMLDateField newInstance(Object obj) {
        return obj instanceof XMLItem ? new XMLDateField((XMLItem)obj) : new XMLDateField((XMLField)obj);
    }
}

